using System;
using System.Linq;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Content;

namespace CthulhuDomain.GameEntities
{
  public class MatrixConfiguration
  {
    public int ID { get; set; }
    public string SetUp { get; set; }

    [ContentSerializerIgnore, XmlIgnore]
    private string[] Rows {
      get {
        var p1 = SetUp.Split(Convert.ToChar(";")).ToList();
        p1.Remove(string.Empty);
        return p1.ToArray();
      }
    }

    [ContentSerializerIgnore, XmlIgnore]
    public string[,] Schema {
      get {
        var y = Rows.Length;
        var x = Rows.Select(row => row.Split(Convert.ToChar(","))).Select(r => r.Length).Concat(new[] { 0 }).Max();
        var schema = new string[x, y];

        for (var i = 0; i < x; i++) {
          for (var j = 0; j < y; j++) {
            schema[i, j] = Rows[j].Split(Convert.ToChar(","))[i];
          }
        }

        return schema;
      }
    }
  }
}